﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class OrderPrint : System.Web.UI.Page, ICallbackEventHandler
{

    public string result;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hidExpressBillImagePath.Value = BLL.Common.GetExpressPicPath();
        }
        Ajax.Utility.RegisterTypeForAjax(typeof(OrderPrint));
        BindTraner();
    }



    private void BindTraner()
    {
        ListItem l=new ListItem("发货单模板","1.jpg");
        dropTraner.Items.Add(l); 
        ListItem ll = new ListItem("退货单模板", "2.jpg");
        dropTraner.Items.Add(ll);
    }



    #region 返回前台初始化数据

    [Ajax.AjaxMethod]
    public DataSet GetData(string aa)
    {
        string[] arr = aa.Split('_');
        DataSet ds = new BLL.ORDERDOC().GetOrderToPrintByTranerIdAndTemplateId(arr[0], arr[1], "");
        return ds;
    }
    #endregion


    #region
    public void RaiseCallbackEvent(string eventArgument)
    {
        
        //可以根据传递的参数不同，调用不同的处理逻辑 
        try
        {
            string[] style = eventArgument.Split('|');
            char[] ch = new char[1] { ',' };
            string[] stanceName = style[0].TrimEnd(ch).Split(',');
            string[] top = style[1].TrimEnd(ch).Split(',');
            string[] left = style[2].TrimEnd(ch).Split(',');
            string[] width = style[3].TrimEnd(ch).Split(',');
            string[] heigth = style[4].TrimEnd(ch).Split(',');
            string[] text = style[5].TrimEnd(ch).Split(',');
            string[] arrTranerTemplate = style[6].Split('_');
            string tranerId = arrTranerTemplate[0];
            string templateId = arrTranerTemplate[1];
            int topRectify = style[7] == "" ? 0 : Convert.ToInt32(style[7]);
            int leftRectify = style[8] == "" ? 0 : Convert.ToInt32(style[8]);

            Model.TRANER traner = new BLL.TRANER().GetModel(tranerId);
            if (traner == null)
            {
                result = "0";
            }

            traner.TRANER_FIELD1 = style[7] == "" ? traner.TRANER_FIELD1 : style[7];
            traner.TRANER_FIELD2 = style[8] == "" ? traner.TRANER_FIELD2 : style[8];
            if (!new BLL.TRANER().Update(traner))
            {
                result = "0";
            }

            new BLL.SubStance().DeleteByTranerId(tranerId, templateId);

            for (int i = 0; i < stanceName.Length; i++)
            {
                new BLL.SubStance().SaveSubStance(tranerId, templateId, stanceName[i], Convert.ToString(Convert.ToInt32(top[i] == "" ? "0" : top[i]) + topRectify), Convert.ToString(Convert.ToInt32(left[i] == "" ? "0" : left[i]) + leftRectify), width[i], heigth[i], text[i]);

            }
            //Share.InsertLog("100100108", "00017");
            result = "1";
        }
        catch (Exception ex)
        {

            result = "0";
        }

    }
    #endregion

    public string GetCallbackResult()
    {
        return result;
    }

}
